849B - Tell Your World - CodeForces Solution


brute force geometry *1600

Please click on ads to support us..

Python Code:

def new(iota, k1):
    z=len(iota)
    if z==0:
        return 0
    elif z==1:
        return 1
    else:
        c1=iota[1][0]-iota[0][0]
        d1=iota[1][1]-iota[0][1]
        e1=d1*iota[0][0]-c1*iota[0][1]
                if 2*c1!=k1*d1:
            return 0
        else:
            for j in range(2, z):
                if c1*iota[j][1]+e1!=d1*iota[j][0]:
                    break
            else:
                                return 1
    return 0

n=int(input())
w=[int(k) for k in input().split()]

k1=w[1]-w[0]
b1=w[0]
iota=[]
for j in range(2, n):
    if k1*j+b1!=w[j]:
        iota.append((w[j], j))
check=new(iota, 2*k1)
            
k1=w[2]-w[0]
b1=2*w[0]
iota=[]
if 2*w[1]!=k1+b1:
    iota.append((w[1], 1))
for j in range(3, n):
    if k1*j+b1!=2*w[j]:
        iota.append((w[j], j))
check=max(check, new(iota, k1))
            
k1=w[2]-w[1]
b1=w[1]-k1
iota=[]
if b1!=w[0]:
    iota.append((w[0], 0))
for j in range(3, n):
    if k1*j+b1!=w[j]:
        iota.append((w[j], j))
check=max(check, new(iota, 2*k1))
            
if check:
    print("YES")
else:
    print("NO")


Comments

Submit
0 Comments
More Questions

1009E - Intercity Travelling
1637B - MEX and Array
224A - Parallelepiped
964A - Splits
1615A - Closing The Gap
4C - Registration System
1321A - Contest for Robots
1451A - Subtract or Divide
1B - Spreadsheet
1177A - Digits Sequence (Easy Edition)
1579A - Casimir's String Solitaire
287B - Pipeline
510A - Fox And Snake
1520B - Ordinary Numbers
1624A - Plus One on the Subset
350A - TL
1487A - Arena
1520D - Same Differences
376A - Lever
1305A - Kuroni and the Gifts
1609A - Divide and Multiply
149B - Martian Clock
205A - Little Elephant and Rozdil
1609B - William the Vigilant
978B - File Name
1426B - Symmetric Matrix
732B - Cormen --- The Best Friend Of a Man
1369A - FashionabLee
1474B - Different Divisors
1632B - Roof Construction